<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">

  
  <title>Android10.0 最近任务Recents功能分析 | 龙之叶的博客</title>

  <link rel="shortcut icon" href="/images/favicon.png">
  <link rel="alternate" href="/atom.xml" title="龙之叶的博客" type="application/atom+xml">
  <meta name="description" content="Android10.0 最近任务Recents功能分析">
<meta property="og:type" content="article">
<meta property="og:title" content="Android10.0 最近任务Recents功能分析">
<meta property="og:url" content="http://longzhiye.top/2023/12/02/2023-12-02/index.html">
<meta property="og:site_name" content="龙之叶的博客">
<meta property="og:description" content="Android10.0 最近任务Recents功能分析">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://longzhiye.top/images/20231202/20231202001.png">
<meta property="og:image" content="http://longzhiye.top/images/20231202/20231202002.png">
<meta property="og:image" content="http://longzhiye.top/images/20231202/20231202003.png">
<meta property="article:published_time" content="2023-12-01T16:00:00.000Z">
<meta property="article:modified_time" content="2024-08-29T02:40:34.914Z">
<meta property="article:author" content="龙之叶">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="SystemUI">
<meta property="article:tag" content="framework">
<meta property="article:tag" content="Launcher">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://longzhiye.top/images/20231202/20231202001.png">

  <meta name="keywords" content=",Android,SystemUI,framework,Launcher">
  <meta name="format-detection" content="telephone=no,email=no">
  <meta name="theme-color" content="#9C27B0">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="龙之叶的博客">
  <meta name="msapplication-starturl" content="http://longzhiye.top/2023/12/02/2023-12-02/">
  <meta name="msapplication-navbutton-color" content="#9C27B0">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-title" content="龙之叶的博客">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/images/favicon.png">

  
    <link rel="canonical" href="http://longzhiye.top/2023/12/02/2023-12-02/">
  

  
  

  
  
  

  
<link rel="stylesheet" href="/css/mdui.css">
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/custom.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
  <script>var a=localStorage.getItem("mdui-theme-layout-dark");if(a){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>var a=localStorage.getItem("mdui-drawer-close");if(!a){document.getElementsByTagName("body")[0].className+=" mdui-drawer-body-left"};</script>
  <header id="header" class="mdui-appbar mdui-appbar-fixed mdui-appbar-scroll-hide mdui-appbar-inset">
  <div class="mdui-toolbar mdui-color-theme">
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="mdui-icon material-icons">menu</i></a>
    <a href="/" class="mdui-typo-headline">龙之叶的博客</a>
    <div class="mdui-toolbar-spacer"></div>
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: '搜索'}"><i class="mdui-icon material-icons">search</i></a>
	<!--
    <a href="/atom.xml" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'RSS'}"><i class="mdui-icon material-icons">rss_feed</i></a>
	-->
  </div>
</header>
<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer mdui-drawer-full-height">
  <script>var a=localStorage.getItem("mdui-drawer-close");if(a){document.getElementById("sidebar").className+=" mdui-drawer-close"};</script>
  <div class="mdui-grid-tile">
    <img src="/images/banner.png" style="height: 160px;">
    <img src="/images/avatar.png" class="avatar-animation" style="position: absolute; top: 10%; left: 24px; width: 64px; height: 64px; border: 2px solid #fff; border-radius: 50%;background-color:#fff;">
    <div class="mdui-grid-tile-actions">
      <div class="mdui-grid-tile-text">
        <div class="mdui-grid-tile-title">龙之叶</div>
        <div class="mdui-grid-tile-subtitle"><i class="mdui-icon material-icons">art_track</i>生命不息，折腾不止</div>
      </div>
      
        <div class="mdui-grid-tile-buttons">
          <a href="mailto:longzhiye163@163.com" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'longzhiye163@163.com'}"><i class="mdui-icon material-icons">email</i></a>
        </div>
      
    </div>
  </div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    <a href="/" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">home</i>
      <div class="mdui-list-item-content">主页</div>
    </a>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-0");if(a){document.getElementsByClassName("mdui-collapse-item")[0].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-deep-orange">archive</i>
        <div class="mdui-list-item-content">归档</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/archives/2025/07/">七月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/06/">六月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/03/">三月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/02/">二月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/01/">一月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/10/">十月 2024<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/09/">九月 2024<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/08/">八月 2024<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/03/">三月 2024<span class="mdui-ripple sidebar_archives-count">5</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/02/">二月 2024<span class="mdui-ripple sidebar_archives-count">11</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/01/">一月 2024<span class="mdui-ripple sidebar_archives-count">9</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/12/">十二月 2023<span class="mdui-ripple sidebar_archives-count">10</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/11/">十一月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/10/">十月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/09/">九月 2023<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/08/">八月 2023<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/06/">六月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/05/">五月 2023<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/04/">四月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/03/">三月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/02/">二月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/09/">九月 2022<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/08/">八月 2022<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/10/">十月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/08/">八月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-1");if(a){document.getElementsByClassName("mdui-collapse-item")[1].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">class</i>
        <div class="mdui-list-item-content">分类</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术<span class="mdui-ripple sidebar_archives-count">98</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E7%94%9F%E6%B4%BB/">生活<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E8%B5%84%E8%AE%AF/">资讯<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E9%80%9A%E7%9F%A5/">通知<span class="mdui-ripple sidebar_archives-count">4</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-2");if(a){document.getElementsByClassName("mdui-collapse-item")[2].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">bookmark</i>
        <div class="mdui-list-item-content">标签</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/tags/ANR/" rel="tag">ANR<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/APP/" rel="tag">APP<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android/" rel="tag">Android<span class="mdui-ripple sidebar_archives-count">89</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android12/" rel="tag">Android12<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android13/" rel="tag">Android13<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android14/" rel="tag">Android14<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AndroidStudio/" rel="tag">AndroidStudio<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AutoDraw/" rel="tag">AutoDraw<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Crash/" rel="tag">Crash<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Foxmail/" rel="tag">Foxmail<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Framework/" rel="tag">Framework<span class="mdui-ripple sidebar_archives-count">20</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GPS%E8%BD%A8%E8%BF%B9%E5%9B%BE/" rel="tag">GPS轨迹图<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Git/" rel="tag">Git<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GitHub/" rel="tag">GitHub<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Google/" rel="tag">Google<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Hexo/" rel="tag">Hexo<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Java/" rel="tag">Java<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Kernel/" rel="tag">Kernel<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Launcher/" rel="tag">Launcher<span class="mdui-ripple sidebar_archives-count">17</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Lib/" rel="tag">Lib<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Linux/" rel="tag">Linux<span class="mdui-ripple sidebar_archives-count">18</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Markdown/" rel="tag">Markdown<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Material-Design/" rel="tag">Material Design<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OS-X/" rel="tag">OS X<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OTA/" rel="tag">OTA<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/QuickTime/" rel="tag">QuickTime<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SSH/" rel="tag">SSH<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Settings/" rel="tag">Settings<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SystemUI/" rel="tag">SystemUI<span class="mdui-ripple sidebar_archives-count">19</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Ubuntu/" rel="tag">Ubuntu<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WPS/" rel="tag">WPS<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Wifi/" rel="tag">Wifi<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WindTerm/" rel="tag">WindTerm<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Windows/" rel="tag">Windows<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/androidmk/" rel="tag">androidmk<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/blog/" rel="tag">blog<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/build/" rel="tag">build<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/feel/" rel="tag">feel<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/framework/" rel="tag">framework<span class="mdui-ripple sidebar_archives-count">50</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/git/" rel="tag">git<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/inotify/" rel="tag">inotify<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/life/" rel="tag">life<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/ninja/" rel="tag">ninja<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/rsync/" rel="tag">rsync<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/standard/" rel="tag">standard<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/test/" rel="tag">test<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1/" rel="tag">企业微信<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E7%94%9F%E6%B4%BB%E6%84%9F%E6%82%9F/" rel="tag">生活感悟<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <a href="/about" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-purple">person</i>
      <div class="mdui-list-item-content">关于</div>
    </a>
  </div>

  <div class="mdui-divider"></div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    
      <a href="/timeline" class="mdui-list-item mdui-ripple">时间轴</a>
    
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-3");if(a){document.getElementsByClassName("mdui-collapse-item")[3].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <div class="mdui-list-item-content">友情链接</div>
        <i class="mdui-list-item-icon mdui-icon material-icons">link</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
          <a href="http://www.niemingzhao.top" target="_blank" class="mdui-list-item mdui-p-l-2 mdui-text-color-theme-accent mdui-ripple" style="justify-content: center;">聂明照的博客</a>
        
        
      </div>
    </div>
  </div>
</aside>

  <main id="main" class="mdui-m-t-5 fadeIn animated">
  
<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  <style>#main article .mdui-card-content .center-block{display:block!important;margin-right:auto!important;margin-left:auto!important}</style>
  <style>#main article .mdui-card-content .text-center{text-align:center!important}</style>
  <article class="mdui-card mdui-m-b-5">
    <header class="mdui-card-media">
      <img src="/images/random/material-14.png" style="max-height: 240px;">
      <div class="mdui-card-media-covered">
        <div class="mdui-card-primary">
          <div class="mdui-card-primary-title">Android10.0 最近任务Recents功能分析</div>
          <div class="mdui-card-primary-subtitle"><i class="iconfont">&#xe697;</i> 2023-12-02 / <i class="iconfont">&#xe601;</i> 龙之叶 &nbsp;&nbsp; <span id="busuanzi_container_page_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_page_pv"></span></span></div>
        </div>
      </div>
      <div class="mdui-card-menu">
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#qrcode', align: 'right'}"><i class="mdui-icon material-icons">devices</i></button>
          <ul class="mdui-menu" id="qrcode">
            
              <li class="mdui-menu-item"><a class="mdui-text-center mdui-ripple">发送到手机</a></li>
            
            <li class="mdui-menu-item" disabled>
              
                <img src="//qr.liantu.com/api.php?w=246&m=10&text=http://longzhiye.top/2023/12/02/2023-12-02/">
              
            </li>
          </ul>
        
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="mdui-icon material-icons">share</i></button>
          <ul class="mdui-menu" id="share_menu">
            <li class="mdui-menu-item">
              <a href="https://service.weibo.com/share/share.php?appkey=&title=Android10.0 最近任务Recents功能分析&url=http://longzhiye.top/2023/12/02/2023-12-02/&pic=http://longzhiye.top/images/favicon.png&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://twitter.com/intent/tweet?text=Android10.0 最近任务Recents功能分析&url=http://longzhiye.top/2023/12/02/2023-12-02/&via=龙之叶" target="_blank" class="mdui-ripple">分享到 Twitter</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.facebook.com/sharer/sharer.php?u=http://longzhiye.top/2023/12/02/2023-12-02/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://plus.google.com/share?url=http://longzhiye.top/2023/12/02/2023-12-02/" target="_blank" class="mdui-ripple">分享到 Google+</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://longzhiye.top/2023/12/02/2023-12-02/&title=Android10.0 最近任务Recents功能分析" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://connect.qq.com/widget/shareqq/index.html?site=龙之叶的博客&title=Android10.0 最近任务Recents功能分析&pics=http://longzhiye.top/images/favicon.png&url=http://longzhiye.top/2023/12/02/2023-12-02/" target="_blank" class="mdui-ripple">分享到 QQ</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://telegram.me/share/url?url=http://longzhiye.top/2023/12/02/2023-12-02/&text=Android10.0 最近任务Recents功能分析" target="_blank" class="mdui-ripple">分享到 Telegram</a>
            </li>
          </ul>
        
      </div>
    </header>
    <div class="mdui-card-content mdui-typo">
      <p>在Android10.0上，Recents功能分布在SystemUI和Launcher3里面集成.</p>
<h3 id="一-初始化"><a href="#一-初始化" class="headerlink" title="一.初始化"></a>一.初始化</h3><p>跟Android8.1类似，先看初始化入口：</p>
<h4 id="1-Recents-java"><a href="#1-Recents-java" class="headerlink" title="1.Recents.java"></a>1.Recents.java</h4><p>Recents继承SystemUI，进程启动后会在Dependency里面通过@Inject进行初始化，然后在SystemUIService里面调用SystemUIApplication的startServicesIfNeeded()里面进行启动：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/recents/Recents.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">final</span> RecentsImplementation mImpl</span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">start</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">//加入callback</span></span><br><span class="line">    mCommandQueue.addCallback(<span class="built_in">this</span>);</span><br><span class="line">    mImpl.onStart(mContext);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>RecentsImplementation替代了之前的RecentsImpl，是一个interface，由其实现类OverviewProxyRecentsImpl来执行操作，关于该类的实例化用到了dagger2，不懂的同学可以去学习一下；</p>
<h4 id="2-OverviewProxyRecentsImpl-java"><a href="#2-OverviewProxyRecentsImpl-java" class="headerlink" title="2.OverviewProxyRecentsImpl.java"></a>2.OverviewProxyRecentsImpl.java</h4><p><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> OverviewProxyService mOverviewProxyService;</span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onStart</span><span class="params">(Context context)</span> &#123;</span><br><span class="line">   </span><br><span class="line">    mOverviewProxyService = Dependency.get(OverviewProxyService.class);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>根据调用关系，在onStart()里面创建了OverviewProxyService对象，看一下具体实现：</p>
<h4 id="3-OverviewProxyService-java"><a href="#3-OverviewProxyService-java" class="headerlink" title="3.OverviewProxyService.java"></a>3.OverviewProxyService.java</h4><p>中间类，在该类内部去绑定远端的service：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Inject</span></span><br><span class="line"><span class="keyword">public</span> <span class="title function_">OverviewProxyService</span><span class="params">(Context context, CommandQueue commandQueue,</span></span><br><span class="line"><span class="params">            NavigationBarController navBarController, NavigationModeController navModeController,</span></span><br><span class="line"><span class="params">            NotificationShadeWindowController statusBarWinController, SysUiState sysUiState,</span></span><br><span class="line"><span class="params">            PipUI pipUI, Optional&lt;Divider&gt; dividerOptional,</span></span><br><span class="line"><span class="params">            Optional&lt;Lazy&lt;StatusBar&gt;&gt; statusBarOptionalLazy,</span></span><br><span class="line"><span class="params">            BroadcastDispatcher broadcastDispatcher)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>(broadcastDispatcher);</span><br><span class="line">    mRecentsComponentName = ComponentName.unflattenFromString(context.getString(</span><br><span class="line">            com.android.internal.R.string.config_recentsComponentName));</span><br><span class="line">    mQuickStepIntent = <span class="keyword">new</span> <span class="title class_">Intent</span>(ACTION_QUICKSTEP)</span><br><span class="line">            .setPackage(mRecentsComponentName.getPackageName());</span><br><span class="line">   </span><br><span class="line">    <span class="comment">// Connect to the service</span></span><br><span class="line">    updateEnabledState();</span><br><span class="line">    startConnectionToCurrentUser();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">startConnectionToCurrentUser</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (mHandler.getLooper() != Looper.myLooper()) &#123;</span><br><span class="line">        mHandler.post(mConnectionRunnable);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        internalConnectToCurrentUser();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">internalConnectToCurrentUser</span><span class="params">()</span> &#123;</span><br><span class="line">    </span><br><span class="line">    <span class="type">Intent</span> <span class="variable">launcherServiceIntent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Intent</span>(ACTION_QUICKSTEP)</span><br><span class="line">                .setPackage(mRecentsComponentName.getPackageName());</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        mBound = mContext.bindServiceAsUser(launcherServiceIntent,</span><br><span class="line">                    mOverviewServiceConnection,</span><br><span class="line">                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,</span><br><span class="line">                    UserHandle.of(getCurrentUserId()));</span><br><span class="line">        &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> IOverviewProxy mOverviewProxy;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">final</span> <span class="type">ServiceConnection</span> <span class="variable">mOverviewServiceConnection</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ServiceConnection</span>() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onServiceConnected</span><span class="params">(ComponentName name, IBinder service)</span> &#123;</span><br><span class="line">      </span><br><span class="line">        mOverviewProxy = IOverviewProxy.Stub.asInterface(service);</span><br><span class="line">       </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>跟随调用关系来看，在构造方法内部，会去执行startConnectionToCurrentUser来调用bindServiceAsUser()去启动service，在onServiceConnected中，通过IOverviewProxy.Stub.asInterface(service)来获取IOverviewProxy实例，后续会用到；<br>Service对应的Intent为android.intent.action.QUICKSTEP_SERVICE，R.string.config_recentsComponentName对应如下，用来获取远端服务的应用包名：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;string name=<span class="string">&quot;config_recentsComponentName&quot;</span> translatable=<span class="string">&quot;false&quot;</span></span><br><span class="line">        &gt;com.android.launcher3/com.android.quickstep.RecentsActivity&lt;/string&gt;</span><br></pre></td></tr></table></figure>
<p>从ComponentName可以看到，被bind的service是在Launcher3里面，接下来一起看一下对应的远端Service；</p>
<h4 id="4-TouchInteractionService-java"><a href="#4-TouchInteractionService-java" class="headerlink" title="4.TouchInteractionService.java"></a>4.TouchInteractionService.java</h4><p><strong>packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java</strong><br>Launcher3内的入口类，通过该类来调用相关逻辑：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">final</span> <span class="type">IBinder</span> <span class="variable">mMyBinder</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">IOverviewProxy</span>.Stub() &#123;</span><br><span class="line">   </span><br><span class="line">    <span class="meta">@BinderThread</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onOverviewToggle</span><span class="params">()</span> &#123;</span><br><span class="line">        mOverviewCommandHelper.onOverviewToggle();</span><br><span class="line">    &#125;</span><br><span class="line">   </span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> IBinder <span class="title function_">onBind</span><span class="params">(Intent intent)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> mMyBinder;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，TouchInteractionService里面创建了IOverviewProxy.Stub实例，然后在onBind()返回；<br>TouchInteractionService是一个Service，在onCreate()里面进行了一些初始化相关的调用：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onCreate</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onCreate();</span><br><span class="line">   </span><br><span class="line">    mDeviceState.runOnUserUnlocked(<span class="built_in">this</span>::onUserUnlocked);</span><br><span class="line">   </span><br><span class="line">    sConnected = <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">@UiThread</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onUserUnlocked</span><span class="params">()</span> &#123;</span><br><span class="line">   </span><br><span class="line">    mOverviewComponentObserver = <span class="keyword">new</span> <span class="title class_">OverviewComponentObserver</span>(<span class="built_in">this</span>, mDeviceState);</span><br><span class="line">    mOverviewCommandHelper = <span class="keyword">new</span> <span class="title class_">OverviewCommandHelper</span>(<span class="built_in">this</span>, mDeviceState,</span><br><span class="line">                mOverviewComponentObserver);</span><br><span class="line">   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，在TouchInteractionService启动后，会创建OverviewComponentObserver实例和OverviewCommandHelper实例，一起看一下这两个类的实现：</p>
<h4 id="5-OverviewComponentObserver-java"><a href="#5-OverviewComponentObserver-java" class="headerlink" title="5.OverviewComponentObserver.java"></a>5.OverviewComponentObserver.java</h4><p><strong>packages/apps/Launcher3/quickstep/src/com/android/quickstep/OverviewComponentObserver.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">OverviewComponentObserver</span><span class="params">(Context context, RecentsAnimationDeviceState deviceState)</span> &#123;</span><br><span class="line">    </span><br><span class="line">    <span class="type">ComponentName</span> <span class="variable">fallbackComponent</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ComponentName</span>(mContext, RecentsActivity.class);</span><br><span class="line">    mFallbackIntent = <span class="keyword">new</span> <span class="title class_">Intent</span>(Intent.ACTION_MAIN)</span><br><span class="line">                .addCategory(Intent.CATEGORY_DEFAULT)</span><br><span class="line">                .setComponent(fallbackComponent)</span><br><span class="line">                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);</span><br><span class="line">    </span><br><span class="line">    updateOverviewTargets();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，在构造方法内部会创建mFallbackIntent，从组成来看，通过该Intent启动RecentsActivity；接下来看一下 updateOverviewTargets()：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">updateOverviewTargets</span><span class="params">()</span> &#123;</span><br><span class="line">   </span><br><span class="line">    mActivityInterface = FallbackActivityInterface.INSTANCE;</span><br><span class="line">    mIsHomeAndOverviewSame = <span class="literal">false</span>;</span><br><span class="line">    mOverviewIntent = mFallbackIntent;</span><br><span class="line">   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在该方法内部，会将mFallbackIntent赋值给mOverviewIntent，后续启动Recents会用到mOverviewIntent；</p>
<h4 id="6-OverviewCommandHelper-java"><a href="#6-OverviewCommandHelper-java" class="headerlink" title="6.OverviewCommandHelper.java"></a>6.OverviewCommandHelper.java</h4><p><strong>packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java</strong><br>启动Recents的直接入口类，最终实现了onOverviewToggle()：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">OverviewCommandHelper</span><span class="params">(Context context, RecentsAnimationDeviceState deviceState,</span></span><br><span class="line"><span class="params">            OverviewComponentObserver observer)</span> &#123;</span><br><span class="line">    </span><br><span class="line">    mRecentsModel = RecentsModel.INSTANCE.get(mContext);</span><br><span class="line">    mOverviewComponentObserver = observer;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">@BinderThread</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onOverviewToggle</span><span class="params">()</span> &#123;</span><br><span class="line">   </span><br><span class="line">    ActivityManagerWrapper.getInstance()</span><br><span class="line">                .closeSystemWindows(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);</span><br><span class="line">    MAIN_EXECUTOR.execute(<span class="keyword">new</span> <span class="title class_">RecentsActivityCommand</span>&lt;&gt;());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以上就是Recents功能在初始化过程中涉及到的关键类，用一张流程图总结一下：</p>
<p><img src="/images/20231202/20231202001.png"></p>
<h3 id="二-启动"><a href="#二-启动" class="headerlink" title="二.启动"></a>二.启动</h3><p>前面分析了初始化涉及到的关键类，系统启动后会启动SystemUI进程，然后进行一系列初始化，接下来看一下进入Recents的流程：<br>关于手势或Key按键触发这一块逻辑处理跟Android8.1处理是一样的，入口都是在PhoneWindowManager，咱们从Recents接收toggleRecentApps()分析：</p>
<h4 id="1-Recents-java-1"><a href="#1-Recents-java-1" class="headerlink" title="1.Recents.java"></a>1.Recents.java</h4><p><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/recents/Recents.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">toggleRecentApps</span><span class="params">()</span> &#123;</span><br><span class="line">   </span><br><span class="line">    mImpl.toggleRecentApps();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="2-OverviewProxyRecentsImpl-java-1"><a href="#2-OverviewProxyRecentsImpl-java-1" class="headerlink" title="2.OverviewProxyRecentsImpl.java"></a>2.OverviewProxyRecentsImpl.java</h4><p><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyRecentsImpl.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">toggleRecentApps</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">// If connected to launcher service, let it handle the toggle logic</span></span><br><span class="line">    <span class="type">IOverviewProxy</span> <span class="variable">overviewProxy</span> <span class="operator">=</span> mOverviewProxyService.getProxy();</span><br><span class="line">    <span class="keyword">if</span> (overviewProxy != <span class="literal">null</span>) &#123;</span><br><span class="line">        <span class="keyword">final</span> <span class="type">Runnable</span> <span class="variable">toggleRecents</span> <span class="operator">=</span> () -&gt; &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="keyword">if</span> (mOverviewProxyService.getProxy() != <span class="literal">null</span>) &#123;</span><br><span class="line">                    mOverviewProxyService.getProxy().onOverviewToggle();</span><br><span class="line">                    mOverviewProxyService.notifyToggleRecentApps();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">catch</span> (RemoteException e) &#123;</span><br><span class="line">                Log.e(TAG, <span class="string">&quot;Cannot send toggle recents through proxy service.&quot;</span>, e);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="comment">//启动runnable</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在runnable内部会通过OverviewProxyService的getProxy()来获取到Launcher3端实现的IOveriewProxy对象引用，然后调用onOverviewToggle()方法：</p>
<h4 id="3-TouchInteractionService-java"><a href="#3-TouchInteractionService-java" class="headerlink" title="3.TouchInteractionService.java"></a>3.TouchInteractionService.java</h4><p><strong>packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@BinderThread</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onOverviewToggle</span><span class="params">()</span> &#123;</span><br><span class="line">    mOverviewCommandHelper.onOverviewToggle();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="4-OverviewCommandHelper-java"><a href="#4-OverviewCommandHelper-java" class="headerlink" title="4.OverviewCommandHelper.java"></a>4.OverviewCommandHelper.java</h4><p><strong>packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@BinderThread</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onOverviewToggle</span><span class="params">()</span> &#123;</span><br><span class="line">   ActivityManagerWrapper.getInstance()</span><br><span class="line">                .closeSystemWindows(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);</span><br><span class="line">   MAIN_EXECUTOR.execute(<span class="keyword">new</span> <span class="title class_">RecentsActivityCommand</span>&lt;&gt;());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，在执行onOverviewToggle()后，实际上是通过Executoe执行了RecentsActivityCommand：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">class</span> <span class="title class_">RecentsActivityCommand</span>&lt;T <span class="keyword">extends</span> <span class="title class_">StatefulActivity</span>&lt;?&gt;&gt; <span class="keyword">implements</span> <span class="title class_">Runnable</span> &#123;</span><br><span class="line">  </span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">RecentsActivityCommand</span><span class="params">()</span> &#123;</span><br><span class="line">        mActivityInterface = mOverviewComponentObserver.getActivityInterface();</span><br><span class="line">      </span><br><span class="line">        <span class="comment">//预加载，Android8.1也有相同的逻辑</span></span><br><span class="line">        mRecentsModel.getTasks(<span class="literal">null</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">     <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">         </span><br><span class="line">         <span class="comment">// Otherwise, start overview.</span></span><br><span class="line">         mListener = mActivityInterface.createActivityInitListener(<span class="built_in">this</span>::onActivityReady);</span><br><span class="line">         mListener.registerAndStartActivity(mOverviewComponentObserver.getOverviewIntent(),</span><br><span class="line">                    <span class="keyword">new</span> <span class="title class_">RemoteAnimationProvider</span>() &#123;</span><br><span class="line">                        <span class="meta">@Override</span></span><br><span class="line">                        <span class="keyword">public</span> AnimatorSet <span class="title function_">createWindowAnimation</span><span class="params">(</span></span><br><span class="line"><span class="params">                                RemoteAnimationTargetCompat[] appTargets,</span></span><br><span class="line"><span class="params">                                RemoteAnimationTargetCompat[] wallpaperTargets)</span> &#123;</span><br><span class="line">                            <span class="keyword">return</span> RecentsActivityCommand.<span class="built_in">this</span>.createWindowAnimation(appTargets,</span><br><span class="line">                                    wallpaperTargets);</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;, mContext, MAIN_EXECUTOR.getHandler(),</span><br><span class="line">                    mAnimationProvider.getRecentsLaunchDuration());</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，最终是通过registerAndStartActivity()来启动了intent，前面分析到mOverviewComponentObserver.getOverviewIntent()对应的就是mFallbackIntent，最终启动了RecentsActivity；<br>用一张流程图总结一下：</p>
<p><img src="/images/20231202/20231202002.png"></p>
<h3 id="三-显示"><a href="#三-显示" class="headerlink" title="三.显示"></a>三.显示</h3><p>在启动RecentsActivity后，会显示最近任务列表，看一下具体工作流程：</p>
<h4 id="1-RecentsActivity-java"><a href="#1-RecentsActivity-java" class="headerlink" title="1.RecentsActivity.java"></a>1.RecentsActivity.java</h4><p><strong>frameworks/base/packages/SystemUI/legacy/recents/src/com/android/systemui/recents/RecentsActivity.java</strong><br>Recents显示Activity</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onCreate</span><span class="params">(Bundle savedInstanceState)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onCreate(savedInstanceState);</span><br><span class="line">  </span><br><span class="line">    setupViews();</span><br><span class="line">   </span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">setupViews</span><span class="params">()</span> &#123;</span><br><span class="line">    inflateRootView(R.layout.fallback_recents_activity);</span><br><span class="line">    setContentView(getRootView());</span><br><span class="line">    mDragLayer = findViewById(R.id.drag_layer);</span><br><span class="line">    mFallbackRecentsView = findViewById(R.id.overview_panel);</span><br><span class="line">    mActionsView = findViewById(R.id.overview_actions_view);</span><br><span class="line">    mDragLayer.recreateControllers();</span><br><span class="line">    mFallbackRecentsView.init(mActionsView);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>RecentsActivity继承了StatefulActivity，有些方法实现是在父类里面执行的，在onCreate()里面执行setupViews()，初始化了FallbackRecentsView，FallbackRecentsView继承了RecentsView，主要逻辑都是在RecentsView里面实现的，直接看RecentsView的实现逻辑：</p>
<h4 id="2-RecentsView-java"><a href="#2-RecentsView-java" class="headerlink" title="2.RecentsView.java"></a>2.RecentsView.java</h4><p><strong>frameworks/base/packages/SystemUI/legacy/recents/src/com/android/systemui/recents/views/RecentsView.java</strong><br>Recents显示主View</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">RecentsView</span><span class="params">(Context context, AttributeSet attrs, <span class="type">int</span> defStyleAttr,</span></span><br><span class="line"><span class="params">            BaseActivityInterface sizeStrategy)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>(context, attrs, defStyleAttr);</span><br><span class="line">    </span><br><span class="line">    mModel = RecentsModel.INSTANCE.get(context);</span><br><span class="line">    mClearAllButton = (ClearAllButton) LayoutInflater.from(context)</span><br><span class="line">                .inflate(R.layout.overview_clear_all_button, <span class="built_in">this</span>, <span class="literal">false</span>);</span><br><span class="line">    mClearAllButton.setOnClickListener(<span class="built_in">this</span>::dismissAllTasks);</span><br><span class="line">    mTaskViewPool = <span class="keyword">new</span> <span class="title class_">ViewPool</span>&lt;&gt;(context, <span class="built_in">this</span>, R.layout.task, <span class="number">20</span> <span class="comment">/* max size */</span>,</span><br><span class="line">                <span class="number">10</span> <span class="comment">/* initial size */</span>);</span><br><span class="line">   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，在构造方法内部，获取了RecentsModel实例，创建了ViewPool实例mTaskViewPool，该mTaskViewPool存储TaskView，对应的layout为 R.layout.task，最大数量为20；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onAttachedToWindow</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onAttachedToWindow();</span><br><span class="line">    updateTaskStackListenerState();</span><br><span class="line">    ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);</span><br><span class="line">    <span class="comment">//当snapshot更新时，会进行回调刷新UI</span></span><br><span class="line">    RecentsModel.INSTANCE.get(getContext()).addThumbnailChangeListener(<span class="built_in">this</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在RecentsView显示时会回调onAttachedToWindow()，在内部执行了updateTaskStackListenerState()，然后做了一些注册回调操作，当有变化时，会进行回调通知来更新UI；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">updateTaskStackListenerState</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">handleTaskStackChanges</span> <span class="operator">=</span> mOverviewStateEnabled &amp;&amp; isAttachedToWindow()</span><br><span class="line">                &amp;&amp; getWindowVisibility() == VISIBLE;</span><br><span class="line">    <span class="keyword">if</span> (handleTaskStackChanges != mHandleTaskStackChanges) &#123;</span><br><span class="line">        mHandleTaskStackChanges = handleTaskStackChanges;</span><br><span class="line">        <span class="keyword">if</span> (handleTaskStackChanges) &#123;</span><br><span class="line">            reloadIfNeeded();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在updateTaskStackListenerState()内部会进行一系列条件判断来确定是否执行reloadIfNeeded()，当首次进入时会执行reloadIfNeeded()：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">reloadIfNeeded</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (!mModel.isTaskListValid(mTaskListChangeId)) &#123;</span><br><span class="line">        mTaskListChangeId = mModel.getTasks(<span class="built_in">this</span>::applyLoadPlan);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>通过RecentsModel的getTasks()来获取任务列表，然后回到applyLoadPlan()，getTasks()逻辑在后面进行分析，先看一下applyLoadPlan()方法的执行逻辑：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">applyLoadPlan</span><span class="params">(ArrayList&lt;Task&gt; tasks)</span> &#123;</span><br><span class="line">    <span class="comment">// Unload existing visible task data</span></span><br><span class="line">    unloadVisibleTaskData();</span><br><span class="line">    <span class="keyword">final</span> <span class="type">int</span> <span class="variable">requiredTaskCount</span> <span class="operator">=</span> tasks.size();</span><br><span class="line">    <span class="keyword">if</span> (getTaskViewCount() != requiredTaskCount) &#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> getTaskViewCount(); i &lt; requiredTaskCount; i++) &#123;</span><br><span class="line">            addView(mTaskViewPool.getView());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (requiredTaskCount &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            addView(mClearAllButton);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Rebind and reset all task views</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> requiredTaskCount - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) &#123;</span><br><span class="line">        <span class="keyword">final</span> <span class="type">int</span> <span class="variable">pageIndex</span> <span class="operator">=</span> requiredTaskCount - i - <span class="number">1</span> + mTaskViewStartIndex;</span><br><span class="line">        <span class="keyword">final</span> <span class="type">Task</span> <span class="variable">task</span> <span class="operator">=</span> tasks.get(i);</span><br><span class="line">        <span class="keyword">final</span> <span class="type">TaskView</span> <span class="variable">taskView</span> <span class="operator">=</span> (TaskView) getChildAt(pageIndex);</span><br><span class="line">        taskView.bind(task, mOrientationState);</span><br><span class="line">    &#125;</span><br><span class="line">    resetTaskVisuals();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在applyLoadPlan()内部，主要执行了四项工作：</p>
<ol>
<li>unloadVisibleTaskData()：将现有visible的task数据进行置空；</li>
<li>根据task数量(首次进入)进行addView，TaskView通过mTaskViewPool的getView()进行获取，最后添加clearAllButton；</li>
<li>对添加完的TaskView进行bind()操作，将对应的task存在TaskView内部，类似setTag()功能；</li>
<li>执行resetTaskVisuals()来刷新加载数据；<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">resetTaskVisuals</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">// Update the set of visible task&#x27;s data</span></span><br><span class="line">    loadVisibleTaskData();</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">loadVisibleTaskData</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">// Update the task data for the in/visible children</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; getTaskViewCount(); i++) &#123;</span><br><span class="line">        <span class="type">TaskView</span> <span class="variable">taskView</span> <span class="operator">=</span> getTaskViewAt(i);</span><br><span class="line">        <span class="type">Task</span> <span class="variable">task</span> <span class="operator">=</span> taskView.getTask();</span><br><span class="line">         <span class="type">int</span> <span class="variable">index</span> <span class="operator">=</span> indexOfChild(taskView);</span><br><span class="line">         <span class="type">boolean</span> <span class="variable">visible</span> <span class="operator">=</span> lower &lt;= index &amp;&amp; index &lt;= upper;</span><br><span class="line">         <span class="keyword">if</span> (visible) &#123;</span><br><span class="line">             <span class="keyword">if</span> (task == mTmpRunningTask) &#123;</span><br><span class="line">                <span class="comment">// Skip loading if this is the task that we are animating into</span></span><br><span class="line">                 <span class="keyword">continue</span>;</span><br><span class="line">             &#125;</span><br><span class="line">             <span class="keyword">if</span> (!mHasVisibleTaskData.get(task.key.id)) &#123;</span><br><span class="line">                 taskView.onTaskListVisibilityChanged(<span class="literal">true</span> <span class="comment">/* visible */</span>);</span><br><span class="line">             &#125;</span><br><span class="line">             mHasVisibleTaskData.put(task.key.id, visible);</span><br><span class="line">         &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
最终在loadVisibleTaskData()里面通过TaskView的onTaskVisibilityChanged(true)来加载数据；</li>
</ol>
<h4 id="3-TaskView-java"><a href="#3-TaskView-java" class="headerlink" title="3.TaskView.java"></a>3.TaskView.java</h4><p>Recents列表中Task对应的显示View<br><strong>frameworks/base/packages/SystemUI/legacy/recents/src/com/android/systemui/recents/views/TaskView.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">bind</span><span class="params">(Task task, RecentsOrientedState orientedState)</span> &#123;</span><br><span class="line">    mTask = task;</span><br><span class="line">    mSnapshotView.bind(task);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onTaskListVisibilityChanged</span><span class="params">(<span class="type">boolean</span> visible)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (mTask == <span class="literal">null</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">        cancelPendingLoadTasks();</span><br><span class="line">    <span class="keyword">if</span> (visible) &#123;</span><br><span class="line">        <span class="comment">// These calls are no-ops if the data is already loaded, try and load the high</span></span><br><span class="line">        <span class="comment">// resolution thumbnail if the state permits</span></span><br><span class="line">        <span class="type">RecentsModel</span> <span class="variable">model</span> <span class="operator">=</span> RecentsModel.INSTANCE.get(getContext());</span><br><span class="line">        <span class="type">TaskThumbnailCache</span> <span class="variable">thumbnailCache</span> <span class="operator">=</span> model.getThumbnailCache();</span><br><span class="line">        <span class="type">TaskIconCache</span> <span class="variable">iconCache</span> <span class="operator">=</span> model.getIconCache();</span><br><span class="line">        mThumbnailLoadRequest = thumbnailCache.updateThumbnailInBackground(</span><br><span class="line">                    mTask, thumbnail -&gt; mSnapshotView.setThumbnail(mTask, thumbnail));</span><br><span class="line">        mIconLoadRequest = iconCache.updateIconInBackground(mTask,</span><br><span class="line">                    (task) -&gt; &#123;</span><br><span class="line">                        setIcon(task.icon);</span><br><span class="line">                        <span class="keyword">if</span> (ENABLE_QUICKSTEP_LIVE_TILE.get() &amp;&amp; isRunningTask()) &#123;</span><br><span class="line">                            getRecentsView().updateLiveTileIcon(task.icon);</span><br><span class="line">                        &#125;</span><br><span class="line">                        mDigitalWellBeingToast.initialize(mTask);</span><br><span class="line">                    &#125;);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            mSnapshotView.setThumbnail(<span class="literal">null</span>, <span class="literal">null</span>);</span><br><span class="line">            setIcon(<span class="literal">null</span>);</span><br><span class="line">            <span class="comment">// Reset the task thumbnail reference as well (it will be fetched from the cache or</span></span><br><span class="line">            <span class="comment">// reloaded next time we need it)</span></span><br><span class="line">            mTask.thumbnail = <span class="literal">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在onTaskListVisibilityChanged()内部，当visible为true时，执行mSnapshotView.setThumbnail()和setIcon()分别来加载缩略图和icon；当visible为false时，将其置空；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">TaskView</span><span class="params">(Context context, AttributeSet attrs, <span class="type">int</span> defStyleAttr)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>(context, attrs, defStyleAttr);</span><br><span class="line">    setOnClickListener((view) -&gt; &#123;</span><br><span class="line">         <span class="keyword">if</span> (getTask() == <span class="literal">null</span>) &#123;</span><br><span class="line">             <span class="keyword">return</span>;</span><br><span class="line">         &#125;</span><br><span class="line">         launchTask(<span class="literal">true</span> <span class="comment">/* animate */</span>);</span><br><span class="line">        &#125;);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">launchTask</span><span class="params">(<span class="type">boolean</span> animate)</span> &#123;</span><br><span class="line">    launchTask(animate, <span class="literal">false</span> <span class="comment">/* freezeTaskList */</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">launchTaskInternal</span><span class="params">(<span class="type">boolean</span> animate, <span class="type">boolean</span> freezeTaskList,</span></span><br><span class="line"><span class="params">            Consumer&lt;Boolean&gt; resultCallback, Handler resultCallbackHandler)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (mTask != <span class="literal">null</span>) &#123;</span><br><span class="line">        ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(mTask.key,</span><br><span class="line">                    opts, resultCallback, resultCallbackHandler);</span><br><span class="line">        getRecentsView().onTaskLaunched(mTask);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在TaskView内部设置了点击事件监听，当点击后会执行launchTask，最终会调用到ActivityManagerWrapper的startActivityFromRecentsAsync()来快速切换到对应的任务；</p>
<h4 id="4-RecentsModel-java"><a href="#4-RecentsModel-java" class="headerlink" title="4.RecentsModel.java"></a>4.RecentsModel.java</h4><p>Recents数据获取功能管理类<br><strong>packages/apps/Launcher3/quickstep/src/com/android/quickstep/RecentsModel.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="title function_">RecentsModel</span><span class="params">(Context context)</span> &#123;</span><br><span class="line">    mContext = context;</span><br><span class="line">    mTaskList = <span class="keyword">new</span> <span class="title class_">RecentTasksList</span>(MAIN_EXECUTOR,</span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">KeyguardManagerCompat</span>(context), ActivityManagerWrapper.getInstance());</span><br><span class="line">    mIconCache = <span class="keyword">new</span> <span class="title class_">TaskIconCache</span>(context, looper);</span><br><span class="line">    mThumbnailCache = <span class="keyword">new</span> <span class="title class_">TaskThumbnailCache</span>(context, looper);</span><br><span class="line">   ActivityManagerWrapper.getInstance().registerTaskStackListener(<span class="built_in">this</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">RecentsModel继承了TaskStackChangeListener，在构造方法内部初始化了RecentsTaskList、TaskIconCache和TaskThumbnailCache实例，注册了registerTaskStackListener回调；分别来获取最近任务列表、获取Task对应的Icon和，</span><br><span class="line">   RecentsTaskList：获取最近任务列表；</span><br><span class="line">   TaskIconCache：获取Task对应的icon，并进行缓存；</span><br><span class="line">   TaskThumbnailCache：获取Task对应的thumbnailData，并进行缓存；</span><br><span class="line">   与Android8<span class="number">.1</span>不同的是，<span class="number">8.1</span>上在获取最近任务列表后会获取任务对应的Thumbnail和Icon，最终封装成Task，在显示时直接通过Task.thumbnail和Task.icon就可以直接显示；<span class="number">11</span>上会通过TaskIconCache和TaskThumbnailCache进行分别存储管理，首次显示或有新的任务，需要通过TaskIconCache和TaskThumbnailCache执行对应的request去获取并进行cache存储；</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="type">int</span> <span class="title function_">getTasks</span><span class="params">(Consumer&lt;ArrayList&lt;Task&gt;&gt; callback)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> mTaskList.getTasks(<span class="literal">false</span> <span class="comment">/* loadKeysOnly */</span>, callback);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>执行getTasks时，实际是通过RecentsTaskList的getTasks()来执行的；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onTaskSnapshotChanged</span><span class="params">(<span class="type">int</span> taskId, ThumbnailData snapshot)</span> &#123;</span><br><span class="line">    mThumbnailCache.updateTaskSnapShot(taskId, snapshot);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> mThumbnailChangeListeners.size() - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) &#123;</span><br><span class="line">        <span class="type">Task</span> <span class="variable">task</span> <span class="operator">=</span> mThumbnailChangeListeners.get(i).onTaskThumbnailChanged(taskId, snapshot);</span><br><span class="line">        <span class="keyword">if</span> (task != <span class="literal">null</span>) &#123;</span><br><span class="line">            task.thumbnail = snapshot;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当Task的snapshot截取完毕后，会收到onTaskSnapshotChanged()回调，先对snapshot进行缓存，然后执行onTaskThumbnailChanged()通知，在RecentsView里面对thumbnail进行更新；</p>
<h4 id="5-RecentsTaskList-java"><a href="#5-RecentsTaskList-java" class="headerlink" title="5.RecentsTaskList.java"></a>5.RecentsTaskList.java</h4><p>获取最近任务列表类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">synchronized</span> <span class="type">int</span> <span class="title function_">getTasks</span><span class="params">(<span class="type">boolean</span> loadKeysOnly, Consumer&lt;ArrayList&lt;Task&gt;&gt; callback)</span> &#123;</span><br><span class="line">    <span class="comment">// Kick off task loading in the background</span></span><br><span class="line">    UI_HELPER_EXECUTOR.execute(() -&gt; &#123;</span><br><span class="line">       <span class="keyword">if</span> (!mResultsBg.isValidForRequest(requestLoadId, loadKeysOnly)) &#123;</span><br><span class="line">            mResultsBg = loadTasksInBackground(Integer.MAX_VALUE, requestLoadId, loadKeysOnly);</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="type">TaskLoadResult</span> <span class="variable">loadResult</span> <span class="operator">=</span> mResultsBg;</span><br><span class="line">       mMainThreadExecutor.execute(() -&gt; &#123;</span><br><span class="line">           mResultsUi = loadResult;</span><br><span class="line">           <span class="keyword">if</span> (callback != <span class="literal">null</span>) &#123;</span><br><span class="line">               ArrayList&lt;Task&gt; result = copyOf(mResultsUi);</span><br><span class="line">               callback.accept(result);</span><br><span class="line">           &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line">   <span class="keyword">return</span> requestLoadId;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在getTasks()内部通过loadTasksInBackgroud()来获取TaskLoadResult对象mResultsBg，然后在主线程里面进行回调，最终执行到RecentsView里面的applyLoadPlan()是在主线程里面刷新UI；先看一下loadTasksInBackground()方法：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">TaskLoadResult <span class="title function_">loadTasksInBackground</span><span class="params">(<span class="type">int</span> numTasks, <span class="type">int</span> requestId, <span class="type">boolean</span> loadKeysOnly)</span> &#123;</span><br><span class="line">    <span class="type">int</span> <span class="variable">currentUserId</span> <span class="operator">=</span> Process.myUserHandle().getIdentifier();</span><br><span class="line">    List&lt;ActivityManager.RecentTaskInfo&gt; rawTasks =</span><br><span class="line">                mActivityManagerWrapper.getRecentTasks(numTasks, currentUserId);</span><br><span class="line">    <span class="comment">// The raw tasks are given in most-recent to least-recent order, we need to reverse it</span></span><br><span class="line">    Collections.reverse(rawTasks);</span><br><span class="line">    <span class="type">TaskLoadResult</span> <span class="variable">allTasks</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">TaskLoadResult</span>(requestId, loadKeysOnly, rawTasks.size());</span><br><span class="line">    <span class="keyword">for</span> (ActivityManager.RecentTaskInfo rawTask : rawTasks) &#123;</span><br><span class="line">        Task.<span class="type">TaskKey</span> <span class="variable">taskKey</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Task</span>.TaskKey(rawTask);</span><br><span class="line">        Task task;</span><br><span class="line">        <span class="keyword">if</span> (!loadKeysOnly) &#123;</span><br><span class="line">            <span class="type">boolean</span> <span class="variable">isLocked</span> <span class="operator">=</span> tmpLockedUsers.get(taskKey.userId);</span><br><span class="line">            task = Task.from(taskKey, rawTask, isLocked);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            task = <span class="keyword">new</span> <span class="title class_">Task</span>(taskKey);</span><br><span class="line">        &#125;</span><br><span class="line">        allTasks.add(task);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> allTasks;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，在loadTasksInBackgroud()内部，通过ActivityManagerWrapper的getRecentTasks()来获取rawTasks，然后反向排序，最后将其处理添加到allTasks，然后返回结果；</p>
<h4 id="6-ActivityManagerWrapper-java"><a href="#6-ActivityManagerWrapper-java" class="headerlink" title="6.ActivityManagerWrapper.java"></a>6.ActivityManagerWrapper.java</h4><p>SystemUI与SystemServer交互类<br><strong>frameworks/base/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> List&lt;RecentTaskInfo&gt; <span class="title function_">getRecentTasks</span><span class="params">(<span class="type">int</span> numTasks, <span class="type">int</span> userId)</span> &#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">       <span class="keyword">return</span> ActivityTaskManager.getService().getRecentTasks(numTasks,RECENT_IGNORE_UNAVAILABLE, userId).getList();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="meta">@NonNull</span> ThumbnailData <span class="title function_">getTaskThumbnail</span><span class="params">(<span class="type">int</span> taskId, <span class="type">boolean</span> isLowResolution)</span> &#123;</span><br><span class="line">    ActivityManager.<span class="type">TaskSnapshot</span> <span class="variable">snapshot</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        snapshot = ActivityTaskManager.getService().getTaskSnapshot(taskId, isLowResolution);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (RemoteException e) &#123;</span><br><span class="line">        Log.w(TAG, <span class="string">&quot;Failed to retrieve task snapshot&quot;</span>, e);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (snapshot != <span class="literal">null</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">ThumbnailData</span>(snapshot);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">ThumbnailData</span>();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">startActivityFromRecents</span><span class="params">(<span class="type">int</span> taskId, ActivityOptions options)</span> &#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="type">Bundle</span> <span class="variable">optsBundle</span> <span class="operator">=</span> options == <span class="literal">null</span> ? <span class="literal">null</span> : options.toBundle();</span><br><span class="line">        ActivityTaskManager.getService().startActivityFromRecents(taskId, optsBundle);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<p>ActivityManagerWrapper提供了跟systemserver交互的接口，相当于Android8.1中的SystemServicesProxy功能；<br>  <br>用一张流程图总结显示过程：</p>
<p><img src="/images/20231202/20231202003.png"></p>
<p>以上就是对Android10.0 Recents功能的分析，功能实现由之前一个进程拆分到两个进程，其他处理基本上保持一致。</p>

      
      <blockquote>
        
        <strong>本文链接：</strong><br><a href="http://longzhiye.top/2023/12/02/2023-12-02/">http://longzhiye.top/2023/12/02/2023-12-02/</a>
      </blockquote>
    </div>
    <footer class="mdui-card-actions">
      
        <a class="mdui-ripple article_categories-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
      
      
        <a class="mdui-ripple article_tags-link" href="/tags/Android/" rel="tag">Android</a><a class="mdui-ripple article_tags-link" href="/tags/Launcher/" rel="tag">Launcher</a><a class="mdui-ripple article_tags-link" href="/tags/SystemUI/" rel="tag">SystemUI</a><a class="mdui-ripple article_tags-link" href="/tags/framework/" rel="tag">framework</a>
      
    </footer>
    
  </article>
  
<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

  <script>$("#main article .mdui-card-content img.fancybox").on("click",function(e){$.fancybox.open({src:$(this).attr("src")});});</script>


  <nav id="paginator">
    
      <a rel="prev" class="extend prev" href="/2023/12/03/2023-12-03/">
        <button aria-label="prev" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></button>
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Ubuntu修改Swap交换空间大小'}">上一篇</span>
      </a>
    
    <div class="spacer"></div>
    
      <a rel="next" class="extend next" href="/2023/11/26/2023-11-26/">
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 10.0 状态栏系统图标显示分析'}">下一篇</span>
        <button aria-label="next" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_forward</i></button>
      </a>
    
  </nav>





</main>
  <footer id="footer" class="mdui-m-t-5 mdui-p-y-3 mdui-color-theme">
  <div class="mdui-p-y-0 mdui-text-center">
    
    
    
    
    
    
    
      <a href="http://github.com/longzhiye" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe7ab;</i></a>
    
    
    
      <a href="https://www.zhihu.com/people/long-zhi-xie-61" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe6c0;</i></a>
    
    
    
      <a href="tencent://tencent:////message/?uin=951898105&Menu=yes" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe651;</i></a>
    
    
  </div>
  <div class="mdui-p-y-1 mdui-text-center">
    Copyright &copy; 2022 - 2025 龙之叶<br>
    Powered by <a href="https://hexo.io/" target="_blank" class="mdui-text-color-theme-accent">Hexo</a>
    <br>
      <span id="busuanzi_container_site_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_site_pv"></span></span> &nbsp;&nbsp;
      <span id="busuanzi_container_site_uv" style="display: none;"><i class="iconfont">&#xe601;</i> <span id="busuanzi_value_site_uv"></span></span>
    
  </div>
</footer>

  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_upward</i></button>
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
<script src="/js/mdui.js"></script>
<script src="/js/script.js"></script>

  
<script src="/custom.js"></script>

</body>
</html>
